//
//  WLMPictureCollectionView.swift
//  WeiBo
//
//  Created by Eric on 2017-01-09.
//  Copyright © 2017 Eric. All rights reserved.
//

import UIKit

private let pictureCellId = "WLMPictureCellId"

class WLMPictureCollectionView: UICollectionView {

    var picture_urls: [WLMPictureInfo]? {
        didSet{
            self.reloadData()
        }
    }
    
    override func awakeFromNib() {
      
        register(WLMPictureCell.self, forCellWithReuseIdentifier: pictureCellId)
        self.dataSource = self
    }

}

extension WLMPictureCollectionView: UICollectionViewDataSource {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return picture_urls?.count ?? 0
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: pictureCellId, for: indexPath) as! WLMPictureCell
        
        cell.pictureInfo = self.picture_urls![indexPath.item]
        
        return cell
    }
}
